home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
jemtex2.zip
/
JIS2MF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-14
|
38KB
|
997 lines
/* -mt -f -A -K -G -O -w */
/* Compile with Turbo-C 2.0 */
/*
This program generates METAFONT code from a Bitmaps file JIS24
Author: Francois Jalbert
'
Date: November 1990
Version: 1.0
Date: April 1991
Version: 2.00
Modifications: - Added four kanjis.
- Fixed incorrect VGA resolution.
- Command line parameter now supported.
- Added automatic mode.
- Added batch mode.
- Updated and improved run-time messages.
- Long triangles added by Mr. Masatoshi Watanabe. Fantastic!
- Fixed and proportional parameters added.
- Standard and dictionary parameters added.
- JIS24 now accessed through low-level I/O channel for speed.
Error Levels: 0 - Normal termination.
1 - Error.
2 - All fonts generated (batch).
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifdef __TURBOC__
#include <process.h>
#endif
#define True 1
#define False 0
/* Number of Bitmaps in JIS24 */
#define BitmapMax 7806
/* Size of each square Bitmap */
#define SizeMax 24
#define SizeMax1 25
/* DOS file name length */
#define FileNameDOS 250 /* includes path */
#define TotalNameDOS 254
/* DOS Record Size */
#define RecSize 72 /* SizeMax*SizeMax/8 */
/* Parameter flag */
#define Flag1 '/' /* DOS style */
#define Flag2 '-' /* UNIX style */
/* Parameter keywords */
#define ParamMax 20
char FixedX1[]="FIXEDWIDTH";
char FixedX2[]="FIXEDX";
char FixedX3[]="NOPROPORTIONALWIDTH";
char FixedX4[]="NOPROPORTIONALX";
char NoFixedX1[]="NOFIXEDWIDTH";
char NoFixedX2[]="NOFIXEDX";
char NoFixedX3[]="PROPORTIONALWIDTH";
char NoFixedX4[]="PROPORTIONALX";
char FixedY1[]="FIXEDHEIGHT";
char FixedY2[]="FIXEDY";
char FixedY3[]="NOPROPORTIONALHEIGHT";
char FixedY4[]="NOPROPORTIONALY";
char NoFixedY1[]="NOFIXEDHEIGHT";
char NoFixedY2[]="NOFIXEDY";
char NoFixedY3[]="PROPORTIONALHEIGHT";
char NoFixedY4[]="PROPORTIONALY";
char Standard1[]="STANDARD";
char NoStandard1[]="DICTIONARY";
char Batch1[]="BATCH";
/* Answer maximum length */
#define AnswerMax 254
typedef char FileNameType[FileNameDOS+1];
typedef char TotalNameType[TotalNameDOS+1];
typedef char ParamType[ParamMax+1];
typedef char AnswerType[AnswerMax+1];
/* Buffer for the Bitmap Data */
struct ColumnType {
unsigned char Data1,Data2,Data3;
};
typedef struct ColumnType BufferType[SizeMax]; /* start at 0 because of fread */
/* The Bitmap array is defined larger to simplify the forthcoming code */
typedef int BitmapType[SizeMax1+1][SizeMax1+1];
struct BitmapsType {
BitmapType Bitmap;
int XMin,XMax,YMin,YMax;
};
/* Run time parameters */
struct RunTimeType {
FileNameType FileName;
/* Batch mode */
int Batch;
/* Automatic mode for JemTeX fonts only */
int Automatic;
/* Fixed or proportional fonts */
int FixedX,FixedY;
/* Standard or dictionary fonts */
int Standard;
};
void Delete(char *String, int Length)
/* Delete the first Length characters of String */
{
int Index;
Index=0;
do String[Index]=String[Index+Length];
while (String[++Index]!='\0');
}
/*------------------------------- GetParameters -----------------------------*/
void SimpleQuery(char Title[], char ChoiceA[], char ChoiceB[], int *Answer)
{
char JChar[2];
int Valid;
do {
Valid=True;
printf("%s:\n",Title);
printf(" a) %s\n",ChoiceA);
printf(" b) %s\n",ChoiceB);
printf("Your choice? ");
if (ferror(stdout)) exit(1);
if (gets(JChar)==NULL) exit(1);
if (strlen(JChar)>1) exit(1);
JChar[0]=toupper(JChar[0]);
if (JChar[0]=='A') *Answer=True;
else
if (JChar[0]=='B') *Answer=False;
else {
Valid=False;
if (putchar('\7')==EOF) exit(1);
}
} while (!Valid);
printf("\n");
if (ferror(stdout)) exit(1);
}
void GetMode(struct RunTimeType *RunTime)
/* Determines if the desired font is a JemTeX font */
{
RunTime->Automatic=False;
if (toupper(RunTime->FileName[0])=='K')
if (toupper(RunTime->FileName[1])=='A')
if (toupper(RunTime->FileName[2])=='N')
if (toupper(RunTime->FileName[3])=='J')
if (toupper(RunTime->FileName[4])=='I')
if(('A'<=toupper(RunTime->FileName[5]))&&(toupper(RunTime->FileName[5])<='H'))
if(('A'<=toupper(RunTime->FileName[6]))&&(toupper(RunTime->FileName[6])<='H'))
if (strlen(RunTime->FileName)==7)
if (toupper(RunTime->FileName[5])<='G') RunTime->Automatic=True;
else
if (toupper(RunTime->FileName[6])<='E') RunTime->Automatic=True;
}
void EchoParameters(struct RunTimeType *RunTime)
/* Echoes the current parameters */
{
printf("Font=%s",RunTime->FileName);
if (RunTime->FixedX) printf(" Fixed Width");
else printf(" Prop. Width");
if (RunTime->FixedY) printf(" Fixed Height");
else printf(" Prop. Height");
if (RunTime->Standard) printf(" Standard");
else printf(" Dictionary");
if (RunTime->Automatic) printf(" Automatic");
else printf(" Manual");
if (RunTime->Batch) printf(" Batch");
printf(".\n");
if (ferror(stdout)) exit(1);
}
void Manual(struct RunTimeType *RunTime)
/* Get parameters from user */
{
printf("METAFONT file name? ");
if (ferror(stdout)) exit(1);
if (gets(RunTime->FileName)==NULL) exit(1);
if (strlen(RunTime->FileName)>FileNameDOS) {
/* File name too long */
printf("\7File name too long: %s...",RunTime->FileName);
exit(1);
}
printf("\n");
if (ferror(stdout)) exit(1);
SimpleQuery("Fixed or proportional font width","Fixed","Proportional",
&RunTime->FixedX);
SimpleQuery("Fixed or proportional font height","Fixed","Proportional",
&RunTime->FixedY);
SimpleQuery("Standard or dictionary font","Standard","Dictionary",
&RunTime->Standard);
/* Batch mode intrinsically isn't manual */
RunTime->Batch=False;
}
void FindBefore(FileNameType FileName)
/* No check for before kanjiaa */
{
if (FileName[6]=='a') {
FileName[6]='h';
FileName[5]--;
}
else
FileName[6]--;
}
void FindAfter(FileNameType FileName)
/* No check for above kanjihe */
{
if (FileName[6]=='h') {
FileName[6]='a';
FileName[5]++;
}
else
FileName[6]++;
}
void ScanMF(FileNameType FileName)
/* Scans backwards for the last JemTeX font generated */
/* Looks first for a .TFM and then for an .MF */
/* If no more fonts to generate, stops with error level 2 */
{
FILE *TestFile;
TotalNameType TotalName;
int Found;
strcpy(FileName,"kanjihf");
do {
FindBefore(FileName);
strcpy(TotalName,FileName);
strcat(TotalName,".tfm");
TestFile=fopen(TotalName,"r");
Found=(TestFile!=NULL);
if (!Found) {
strcpy(TotalName,FileName);
strcat(TotalName,".mf");
TestFile=fopen(TotalName,"r");
Found=(TestFile!=NULL);
}
} while (!Found && strcmp(FileName,"kanjiaa"));
if (Found) {
if (fclose(TestFile)==EOF) exit(1);
if (strcmp(FileName,"kanjihe")) FindAfter(FileName);
else {
printf("\7All JemTeX fonts generated!\n");
exit(2);
}
}
}
void Automate(struct RunTimeType *RunTime, int argc, char *argv[])
/* Get parameters from command line */
/* Finds the next font to be generated if in batch mode */
{
int ParamIndex,ParamLength,Index;
ParamType Param;
/* Defaults */
strcpy(RunTime->FileName,"kanjiaa");
RunTime->FixedX=False;
RunTime->FixedY=False;
RunTime->Standard=True;
RunTime->Batch=False;
/* Scan command line parameters */
/* 0th is program's name, last is NULL */
for (ParamIndex=1 ; ParamIndex<argc ; ParamIndex++) {
ParamLength=strlen(argv[ParamIndex]);
if (ParamLength>ParamMax) {
/* Keyword too long */
printf("\7Invalid command line parameter: %s...",argv[ParamIndex]);
exit(1);
}
strcpy(Param,argv[ParamIndex]);
if ((Param[0]==Flag1) || (Param[0]==Flag2)) {
/* Not a font name */
/* Delete 1 char at t